#include "DeviceManager.h"

void DeviceManager::createDevice() {
	asynDtControl = std::make_shared<AsyncXRayCamera>();
	vjControl = std::make_shared<VJ::TubeVJ>();
	if (IniManager::GetInstance()->getBeltEnabledStatus()) {
		beltControl = std::make_shared<BeltControl>();
	}
	else {
		beltControl = nullptr;
	}

	//plcControl = std::make_shared<PlcControl>();
	plcControl = std::make_shared<AsyncPlcControl>();

	if (IniManager::GetInstance()->getIOEnabledStatus()) {
		ioControl = std::make_shared<AsyncIOControl>();
	}
	else {
		ioControl = nullptr;
	}
	
	blowControl = std::make_shared<BlowControl>();
	diskMonitor = std::make_shared<DiskMonitor>();
	hasCreateDevice = true;
}

void DeviceManager::destroyDevice() {
	asynDtControl = nullptr;
	vjControl = nullptr;
	beltControl = nullptr;
	plcControl = nullptr;
	ioControl = nullptr;
	blowControl = nullptr;
	diskMonitor = nullptr;
}

std::shared_ptr<AsyncXRayCamera> DeviceManager::getXRayCamera() {
	if (!hasCreateDevice)
		createDevice();
	return asynDtControl;
}

std::shared_ptr<VJ::TubeVJ>	 DeviceManager::getXRayTube() {
	if (!hasCreateDevice)
		createDevice();
	return vjControl;
}

std::shared_ptr<BeltControl> DeviceManager::getBelt() {
	if (!hasCreateDevice)
		createDevice();
	return beltControl;
}
std::shared_ptr<AsyncPlcControl> DeviceManager::getPlc() {
//std::shared_ptr<PlcControl> DeviceManager::getPlc() {
	if (!hasCreateDevice)
		createDevice();
	return plcControl;
}
std::shared_ptr<AsyncIOControl> DeviceManager::getIO() {
	if (!hasCreateDevice)
		createDevice();
	return ioControl;
}

std::shared_ptr<BlowControl> DeviceManager::getBlow() {
	if (!hasCreateDevice)
		createDevice();
	return blowControl;
}

std::shared_ptr<DiskMonitor> DeviceManager::getDiskMonitor()
{
	if (!hasCreateDevice)
		createDevice();
	return diskMonitor;
}
